'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:FinanceAddvaluetaxCtrl
 * @description
 * # FinanceAddvaluetaxCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
  .controller('FinanceAddvaluetaxCtrl', function ($scope, openApi, Util, $location, $routeParams, FormSubmit) {
    var id = $scope.process_id = $routeParams.id
    $scope.rateList = [{
      key: "无",
      value: "无"
    }, {
      key: "1%",
      value: "1%"
    }, {
      key: "2%",
      value: "2%"
    }, {
      key: "3%",
      value: "3%"
    }, {
      key: "5%",
      value: "5%"
    }, {
      key: "6%",
      value: "6%"
    }, {
      key: "9%",
      value: "9%"
    }, {
      key: "10%",
      value: "10%"
    }, {
      key: "11%",
      value: "11%"
    }, {
      key: "13%",
      value: "13%"
    }, {
      key: "16%",
      value: "16%"
    }, {
      key: "17%",
      value: "17%"
    }, {
      key: "免税",
      value: "免税"
    }, {
      key: "其他",
      value: "其他"
    }];
    $scope.issueTypeList = [{
      key: "普通发票",
      value: "普通发票"
    }, {
      key: "专用发票",
      value: "专用发票"
    }];
    $scope.chooseinfo = function () {
      var relModuleObj = {
        name: "FinanceAddvaluetaxCtrl",
        selectTab: "project_money_select",
        selectTabContent: "工程名称"
      };
      // 清掉关联的编号
      var params = $scope.param;
      Util.savaParamForReview(params, id);
      Util.savaDataforsearch(relModuleObj);
      $location.path("finance/choosepeople")
    };
    $scope.choosePayment = function () {
      if (!$scope.param.projectName) {
        Util.Toast("请先选择工程名称");
        return;
      }
      var relModuleObj = {
        selectTab: "select_payment_invoice",
        propertyName: "paymentInvoiceNo",
        propertyValue: "fileNo",
        param: {
          contractNo: $scope.param.contractNo
        },
        selectTabContent: "发票编号"
      };
      // 清掉关联的编号
      var params = $scope.param;
      Util.savaParamForReview(params, id);
      Util.savaDataforsearch(relModuleObj);
      $location.path("finance/choosemultinfo")
    };
    $scope.chooseRecord = function () {
      if (!$scope.param.projectName) {
        Util.Toast("请先选择工程名称");
        return;
      }
      var relModuleObj = {
        selectTab: "select_tax_record",
        param: {
          contractNo: $scope.param.contractNo
        },
        propertyName: "taxRecordNo",
        propertyValue: "fileNo",
        selectTabContent: "税票编号"
      };
      // 清掉关联的编号
      var params = $scope.param;
      Util.savaParamForReview(params, id);
      Util.savaDataforsearch(relModuleObj);
      $location.path("finance/choosemultinfo")
    };
    $scope.submit = function (operationId) {
      // 底部类型end
      var options = {};
      // 流程id
      options.id = id;
      // 根据operationId判断是草稿还是提交
      options.operationId = operationId;
      options.urlParam = openApi.addedValueTax;
      options.param = angular.copy($scope.param, {});
      FormSubmit.submit(options, $scope);
    };
    $scope.validate = function () {
      if (!$scope.param.projectName) {
        Util.Toast("请选择工程名称");
        return;
      }
      if (!$scope.param.issueType) {
        Util.Toast("请选择开票类型");
        return;
      }
      if (!$scope.param.amount) {
        if ($scope.param.amount !== 0) {
          Util.Toast("请填写税票金额");
          return;
        }
      }
      if (!$scope.param.taxRate) {
        Util.Toast("请填写税率");
        return;
      }
      if (!$scope.validation.passvalidation) {
        Util.Toast($scope.validation.tip);
        return;
      }
      return true;
    }
    var init = function () {
      // 获取回显的详细信息
      Util.getDetailData(id, function (data) {
        $scope.param = data;
      });
    };
    // 初始化
    init();
  });
